package com.example.utils;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    private static final int OK_CODE=200;
    private static final String OK_MSG="SUCCESS";
    private static final int SERVER_ERROR=200;
    private static final String SERVER_ERROR_MSG="服务器异常";
    private static final int UNAUTHORIZED=401;
    private static final String UNAUTHORIZED_MSG="未认证";

    private static final int PERMISSION_DEBUED=403;
    private static final  String PERMISSION_DENIED_MSG="权限不足";

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result() {
        this(OK_CODE,OK_MSG);
    }
    public static Result success(){
        return new Result();
    }
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>(OK_CODE, OK_MSG, data);
        return result;
    }
    public static Result error(Integer code,String msg){
        return new Result(code,msg);
    }
    public static Result unauthorized(){
        return new Result(UNAUTHORIZED,UNAUTHORIZED_MSG);
    }
    public static Result permissionDenied(){
        return new Result(PERMISSION_DEBUED,PERMISSION_DENIED_MSG);
    }
}
